#-------------------------------------------------
#
# Project created by QtCreator 2015-08-01T00:00:11
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

FRAMEWORK_ROOT = $$PWD/../../..

include($$PWD/config.pri)
include($${FRAMEWORK_ROOT}/source/common/build.pri)

TEMPLATE = app
TARGET = $$qtLibraryTarget(keygen)
DESTDIR = $${FRAMEWORK_ROOT}/bin

DEFINES += \
    USE_ENCRYPT

## - import libraries -

## sources

INCLUDEPATH += $$PWD

HEADERS += \
    mainwindow.h

SOURCES += \
    main.cpp \
    mainwindow.cpp

RESOURCES += \
    resource/resource.qrc

##################################################
## import libraries
##################################################

# encrypt

contains(DEFINES, USE_ENCRYPT) {
    win32:CONFIG(release, debug|release): LIBS += -L$${FRAMEWORK_ROOT}/lib/core/encrypt -lencrypt
    else:win32:CONFIG(debug, debug|release): LIBS += -L$${FRAMEWORK_ROOT}/lib/core/encrypt -lencryptd
    else:macx: LIBS += -framework encrypt -F$${FRAMEWORK_ROOT}/lib/core
    else:unix: LIBS += -L$${FRAMEWORK_ROOT}/lib/core/encrypt -lencrypt

    macx:{
        INCLUDEPATH += $${FRAMEWORK_ROOT}/lib/core/encrypt.framework/Versions/Current/Headers
        DEPENDPATH += $${FRAMEWORK_ROOT}/lib/core/encrypt.framework/Versions/Current/Headers
    } else {
        INCLUDEPATH += $${FRAMEWORK_ROOT}/lib/core/encrypt/include
        DEPENDPATH += $${FRAMEWORK_ROOT}/lib/core/encrypt/include
    }
    DEFINES += ENCRYPT_DLL
}

## copy libraries

copyCommand = @echo ---- module $${TARGET}: copy libraries ----

macx: {
    ##
} else:win32|unix: {

    destdir = $${FRAMEWORK_ROOT}/bin
    srcfiles =

    ## lib-suffix
    win32:CONFIG(debug, debug|release):lib_suffix=d.dll
    else:win32:CONFIG(release, debug|release):lib_suffix=.dll
    else:unix:lib_suffix=.so

    win32:destdir = $$replace(destdir, /, \\)

    # encrypt
    srcfiles += $${FRAMEWORK_ROOT}/lib/core/encrypt/encrypt
    ## copy files
    for (srcfile, srcfiles) {
        srcfile = $$srcfile$${lib_suffix}
        exists("$$srcfile"): {
            win32:srcfile = $$replace(srcfile, /, \\)
            copyCommand += && $(COPY_FILE) "$$srcfile" "$$destdir"
        }
    }
}

first.depends = $(first)
keygen.commands = $$copyCommand
first.depends += keygen

QMAKE_EXTRA_TARGETS += first \
    keygen
